home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / morse / staton / spch_lib.c < prev    next >
C/C++ Source or Header  |  1994-04-21  |  8KB  |  319 lines

  1. /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
  2. /*  Copyright (C) 1994 Ken Staton  */
  3. /*      All Rights Reserved        */
  4. /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
  5.  
  6. /*******************************************************************
  7. **    The WINEXEC functions require                                 **
  8. **  Options:Project:Linker:Catagory(Windows Libraries: TOOLHELP)  **
  9. *******************************************************************/
  10.  
  11. /*
  12. ** 
  13. **    This program is the library manager for binary speech records
  14. **    used in digitized speech implementations.
  15. **
  16. **    It compiles a source file into an assembler formatted text file
  17. **    and a binary data file.
  18. **
  19. **    The source file format is:
  20. **        Label    filename
  21. **        Label    filename
  22. **          :         :
  23. **          :         :
  24. **        Label    filename
  25. **
  26. **    Where "Label" is used as the label for the binary data in
  27. **    the assembler text file, and "filename" is the name of the
  28. **    binary data corresponding to label.
  29. **
  30. **    K Staton 6/1/93
  31. **
  32. **    The WINEXEC functions require 
  33. **  Options:Project:Linker:Catagory(Windows Libraries: TOOLHELP)
  34. */       
  35.  
  36. /*
  37.  
  38. TEXT FILE OUPUT...
  39. TEXT file "directory":
  40. LABEL0    DW    start0            ;filename
  41.         DW    stop0
  42. LABEL1    DW    start1            ;filename
  43.         DW    stop1
  44.         .
  45.         .
  46.         .
  47. LABELn    DW    startn            ;filename
  48.         DW    stopn             
  49.         
  50. BINARY FILE OUTPUT...
  51. BIN file data:
  52. 0data0                        {start0=$+0x1000}
  53.   .
  54.   .
  55.   .
  56. 0datay                        {stop0=$+y+0x1000}
  57. 1data0                        {start1=$+y+1+0x1000}
  58.   .
  59.   .
  60.   .
  61. 1dataz 
  62.   .
  63.   .
  64.  
  65. assuming binary data starts at 0x1000.
  66.  
  67. */          
  68.  
  69.     
  70. #define BASE_ADDR 0x1000; /* default */
  71.  
  72. #include <windows.h>
  73. #include <stdio.h>    
  74. #include <io.h> 
  75. #include <stdlib.h>
  76. #include <malloc.h>  
  77. #include <math.h> 
  78. #include <string.h>    
  79. #include <toolhelp.h>
  80.  
  81.                    
  82. /* GLOBALS */                    
  83. FILE *infile_t, *infile_b;
  84. FILE *outfile_t, *outfile_b;
  85. FILE *testfile;     
  86.  
  87. char SrcFile[255];
  88. char SrcFileTxt[255];
  89. char TgtFileBin[255],TgtFileTxt[255];
  90. char WrkFilePCM[255];  
  91. char label[16],addrl_t[16],addrh_t[16];
  92.  
  93.                 
  94. void main(void)
  95. {  
  96. unsigned char data;
  97. int i;
  98. unsigned int addrl,addrh;
  99. char fname[255],cmdstr[255],filestr[255];
  100. char *dot;
  101. /*MSG msg;  */
  102. HINSTANCE ghInstChild; 
  103. TASKENTRY te;    
  104. int done;
  105.           
  106.  
  107. _wabout("Creates speech files for assembly.\nCopyright (C) 1994 Ken Staton.\nAll Rights Reserved.\n");    
  108.           
  109.           
  110. printf("Enter the library name (no extension): \n");
  111. scanf("%s",SrcFile); 
  112.  
  113. strcpy(SrcFileTxt,SrcFile);    /* Source file is text */
  114. strcat(SrcFileTxt,".src"); 
  115.  
  116. strcpy(TgtFileTxt,SrcFile);    /* Target text file for inclusion in assy source */
  117. strcat(TgtFileTxt,".txt");
  118.  
  119. strcpy(TgtFileBin,SrcFile);    /* Target binary file for programming EPROM */
  120. strcat(TgtFileBin,".bin");
  121.  
  122. /* OPEN FILES */
  123.    
  124. /* Open source file for read */
  125.  
  126. if( (infile_t  = fopen( SrcFileTxt, "rt" )) == NULL )
  127.   {
  128.   printf("The file %s was not opened\n",SrcFileTxt);
  129.   exit(-1);
  130.   }
  131. else
  132.   {
  133.   printf( "The file %s was opened\n",SrcFileTxt );
  134.   }  
  135.  
  136. /* open text output file */
  137.  
  138. if( (outfile_t = fopen( TgtFileTxt, "w+t" )) == NULL )
  139.   {
  140.   printf( "The file %s was not opened\n",TgtFileTxt );
  141.   exit(-1);
  142.   }
  143. else
  144.   {
  145.   printf( "The file %s was opened\n",TgtFileTxt );
  146.   }
  147.  
  148. /* open binary output file */                          
  149.  
  150. if( (outfile_b = fopen( TgtFileBin, "w+b" )) == NULL )
  151.   {
  152.   printf( "The file %s was not opened\n",TgtFileBin );
  153.   exit(-1);
  154.   }
  155. else
  156.   {
  157.   printf( "The file %s was opened\n",TgtFileBin );
  158.   }
  159.  
  160. /* base address... */
  161.  
  162. printf("Enter the base address in HEX: \n");
  163. scanf("%X",&addrl);
  164.  
  165. /* start processing library... */
  166.  
  167. /* addrl=BASE_ADDR; */     /* default disabled! */
  168. fscanf(infile_t,"%s %s",label,fname);
  169. while (feof(infile_t) == 0)
  170.   {  
  171.   dot=strchr(fname,'.');        /* find "." in filename */
  172.   fname[dot-fname]='\000';        /* replace with NULL terminator */
  173.   /* form command string... */
  174.   strcpy(cmdstr,"voc2bin.exe ");
  175.   strcat(cmdstr,fname);
  176.   strcat(cmdstr,".VOC ");
  177.   strcat(cmdstr,fname);
  178.   strcat(cmdstr,".BIN");
  179.   
  180.   /* call voc2bin.exe fname.VOC fname.BIN */
  181.   ghInstChild=(HINSTANCE)WinExec(cmdstr, SW_SHOWMINIMIZED);  
  182.  
  183.   /* test for done */ 
  184.   done=0;
  185.   while (!done)
  186.     {        
  187.     done=1; /* assume done */
  188.     te.dwSize=sizeof(TASKENTRY);
  189.     TaskFirst(&te); 
  190.     if (te.hInst==ghInstChild) done=0;
  191.     while (TaskNext(&te))
  192.       {
  193.       if (te.hInst==ghInstChild) done=0;
  194.       _wyield();
  195.       }
  196.     _wyield();
  197.     }
  198.  
  199.   
  200.   /* form command string */
  201.   strcpy(cmdstr,"adpcm2.exe ");
  202.   strcat(cmdstr,fname);
  203.   strcat(cmdstr,".BIN ");
  204.   strcat(cmdstr,fname);
  205.   strcat(cmdstr,".PCM");   
  206.   
  207.   /* call adpcm2 fname.BIN fname.PCM */
  208.   ghInstChild=(HINSTANCE)WinExec(cmdstr, SW_SHOWMINIMIZED);  
  209.  
  210.   /* test for done */ 
  211.   done=0;
  212.   while (!done)
  213.     {        
  214.     done=1; /* assume done */
  215.     te.dwSize=sizeof(TASKENTRY);
  216.     TaskFirst(&te); 
  217.     if (te.hInst==ghInstChild) done=0;
  218.     while (TaskNext(&te))
  219.       {
  220.       if (te.hInst==ghInstChild) done=0;
  221.       _wyield();
  222.       }
  223.     _wyield();
  224.     }
  225.  
  226.  
  227.   
  228.   /* open ____.pcm file */      
  229.   strcpy(WrkFilePCM,fname);
  230.   strcat(WrkFilePCM,".PCM");
  231.   
  232.   if( (infile_b  = fopen( WrkFilePCM, "rb" )) == NULL )
  233.     {
  234.     printf("The file %s was not opened\n",WrkFilePCM);
  235.     /*exit(-1);*/
  236.     }
  237.   else
  238.     {
  239.     printf( "The file %s was opened\n",WrkFilePCM );
  240.     }  
  241.   
  242.   /* append binary ____.pcm file to speech.bin output */
  243.   i=1;
  244.   data=fgetc(infile_b);   
  245.   while (feof(infile_b) == 0)
  246.     { 
  247.     i++;  
  248.     fputc(data,outfile_b);   
  249.     data=fgetc(infile_b);
  250.     }
  251.   i-=1;
  252.   fputc('\000',outfile_b);        /* write terminator byte */
  253.                                 /* 8051 loop ends when DPTR = end
  254.                                 ** and this is a pre-test, so it
  255.                                 ** doesn't get output.
  256.                                 */ 
  257.       
  258.   if (infile_b != NULL)
  259.     if( fclose( infile_b ) )
  260.       printf( "The file %s was not closed\n",WrkFilePCM );       
  261.  
  262.   _itoa(addrl,addrl_t,16);        /* previously set */
  263.   
  264.   addrh=addrl+i;                /* i > 0 includes terminator byte */
  265.                                   /* addrh = addrl when i = zero bytes */
  266.   _itoa(addrh,addrh_t,16);
  267.   
  268.   addrl=addrl+i+1;                /* set to next */
  269.     
  270.   /* write text output with columns aligned */  
  271.   if (strlen(addrl_t)==2)
  272.      fprintf(outfile_t,"%s\t.DW\t000%sH\t;%s\n",label,addrl_t,fname);
  273.   if (strlen(addrl_t)==3)
  274.      fprintf(outfile_t,"%s\t.DW\t00%sH\t;%s\n",label,addrl_t,fname);
  275.   if (strlen(addrl_t)==4)
  276.      fprintf(outfile_t,"%s\t.DW\t0%sH\t;%s\n",label,addrl_t,fname);
  277.      
  278.   if (strlen(addrh_t)==2)
  279.      fprintf(outfile_t,"\t.DW\t000%sH\n",addrh_t); 
  280.   if (strlen(addrh_t)==3)
  281.      fprintf(outfile_t,"\t.DW\t00%sH\n",addrh_t);
  282.   if (strlen(addrh_t)==4)
  283.      fprintf(outfile_t,"\t.DW\t0%sH\n",addrh_t);
  284.   
  285.   /* cleanup...
  286.   ** delete ____.bin file
  287.   ** delete ____.pcm file
  288.   */     
  289.   
  290.   strcpy(filestr,fname);
  291.   strcat(filestr,".BIN");                
  292.   if( remove( filestr ) == -1 )
  293.       printf( "Could not delete %s",filestr );
  294.    else
  295.       printf( "Deleted %s \n",filestr );
  296.                        
  297.   strcpy(filestr,fname);
  298.   strcat(filestr,".PCM");                       
  299.   if( remove( filestr ) == -1 )
  300.       printf( "Could not delete %s",filestr );
  301.    else
  302.       printf( "Deleted %s \n",filestr );  
  303.   
  304.   fscanf(infile_t,"%s %s",label,fname);  /* get next line... */
  305.   } /* while (feof(infile_t) == 0) */                       
  306.  
  307.  
  308.  
  309. /* Close streams */
  310. if( fclose( infile_t ) )
  311.   printf( "The file %s was not closed\n",SrcFileTxt ); 
  312. if( fclose( outfile_t ) )
  313.   printf( "The file %s was not closed\n",TgtFileTxt ); 
  314. if( fclose( outfile_b ) )
  315.   printf( "The file %s was not closed\n",TgtFileBin );  
  316.  
  317. printf("Done.\n");  
  318.  
  319. }    /* end main */